namespace SG3L_RAG.Domain.Entities
{
    public class PagedResult<T>
    {
        public IEnumerable<T> Items { get; set; } = new List<T>();
        public int CurrentPage { get; set; }
        public int PageSize { get; set; }
        public int TotalCount { get; set; }
        public int TotalPages => (int)Math.Ceiling((double)TotalCount / PageSize);
        public bool HasPreviousPage => CurrentPage > 1;
        public bool HasNextPage => CurrentPage < TotalPages;

        public PagedResult()
        {
        }

        public PagedResult(IEnumerable<T> items, int currentPage, int pageSize, int totalCount)
        {
            Items = items;
            CurrentPage = currentPage;
            PageSize = pageSize;
            TotalCount = totalCount;
        }

        public static PagedResult<T> Create(IEnumerable<T> source, int page, int pageSize)
        {
            var totalCount = source.Count();
            var items = source.Skip((page - 1) * pageSize).Take(pageSize);

            return new PagedResult<T>(items, page, pageSize, totalCount);
        }
    }

    public class PageRequest
    {
        public int Page { get; set; } = 1;
        public int PageSize { get; set; } = 12;

        public void Validate()
        {
            if (Page < 1) Page = 1;
            if (PageSize < 1) PageSize = 12;
            if (PageSize > 100) PageSize = 100; // 限制最大页面大小
        }
    }
}
